package com.example.my.agiftthat.ui.classify.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.my.agiftthat.R;
import com.example.my.agiftthat.ui.home.fragment.TabHomeAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by My on 2016/12/3.
 */

public class FragmentClassify extends Fragment {
    private Context mContext = null;
    private TabLayout tabLayout_classify;
    private ViewPager viewPager_classify;
    private List<Fragment> mList = new ArrayList<>();
    private String[] mArrClassifyTitles = null;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_classify, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tabLayout_classify = (TabLayout) view.findViewById(R.id.tabLayout_classify);
        viewPager_classify = (ViewPager) view.findViewById(R.id.viewpager_classify);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mArrClassifyTitles = getResources().getStringArray(R.array.mArrClassifyTitles);
        StrategyFragment fragment = new StrategyFragment();
        mList.add(fragment);
        SingleFragment fragment1 = new SingleFragment();
        mList.add(fragment1);
        TabHomeAdapter adapter = new TabHomeAdapter(getChildFragmentManager(), mList, mArrClassifyTitles);
        viewPager_classify.setAdapter(adapter);
        tabLayout_classify.setupWithViewPager(viewPager_classify);
    }
}
